public class Problem35 {
	public static void main(String[] args) {
		int N = 1000000;
		int[] sieve = new int[N];

		sievePrimes(sieve);

		int count = 0;
		for (int i = 2; i < N; ++i) {
			if (sieve[i] == 0) {
				StringBuilder sb = new StringBuilder();
				sb.append(i);
				int len = sb.length();
				sb.append(i);

				int j = 0;
				for (; j < len; ++j) {
					int rot = Integer.parseInt(sb.substring(j, j + len));
					if (sieve[rot] == 1)
						break;
				}

				if (j < len)
					continue;
				count++;		
			}
		}

		System.out.println("" + count);
	}

	private static void sievePrimes(int[] sieve) {
		for (int i = 2; i < sieve.length/2; ++i) {
			for (int j = 2*i; j < sieve.length; j += i) {
				sieve[j] = 1;	
			}
		}
	}
}
